﻿using Benlai.Model.Doc;
using Benlai.Dac.Doc;
using Benlai.Util;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;


namespace Benlai.Bll.Doc
{
    public class InterfaceDocManager
    {
        public List<InterfaceDocModel> GetList()
        {
            InterfaceDocDac dac = new InterfaceDocDac();
            dac.SortPropertyName = "No";
            int recordCount = 0;
            return dac.GetList(1, 200, out recordCount);
        }

        public InterfaceDocModel Get(string no)
        {
            InterfaceDocDac dac = new InterfaceDocDac();
            dac.SortPropertyName = "No";
            var list = dac.Get(no);
            if (list == null || list.Count <= 0)
                return null;
            return list[0];
        }

        public List<InterfaceDocModel> GetByName(string name)
        {
            InterfaceDocDac dac = new InterfaceDocDac();
            return dac.GetByName(name);
        }

        public void Set(InterfaceDocModel model)
        {
            InterfaceDocDac dac = new InterfaceDocDac();
            dac.Set(model);
        }

        public void Publish(string fileName, string htmlcontent)
        {

            if (File.Exists(fileName))
            {
                File.Delete(fileName);
            }

            using (File.Create(fileName))
            {
            }

            //StreamWriter
            using (StreamWriter sw = new StreamWriter(fileName))
            {
                sw.Write(htmlcontent);
                sw.Flush();
            }
            
        }
    }
}
